# 1.
# 父类
class Student(object):
    def __init__(self, name, num, age, sex):
        self.name = name
        self.num = num
        self.age = age
        self.sex = sex

    def study(self):
        print("学习")


# 小学生类
class Pupil(Student):
    def __init__(self, name, num, age, sex):
        super().__init__(name, num, age, sex)

    def study(self):
        print(f"{self.name}学习的内容是:语文 数学 英语")

    def fight(self):
        print(f"{self.name}喜欢打架")


# 中学生类
class Middle(Student):
    def __init__(self, name, num, age, sex, height, weight):
        super().__init__(name, num, age, sex)  # 继承父类
        self.weight = weight
        self.height = height

    def study(self):
        print(f"{self.name}学习的内容是:语数外 生物化 史地政")

    def love(self):
        print(f"{self.name}喜欢搞对象!")


# 大学生类
class Univercity(Student):
    def __init__(self, name, num, age, sex):
        super().__init__(name, num, age, sex)

    def study(self):
        print(f"{self.name}逃课中.......")

    def play_game(self):
        print(f"{self.name}喜欢玩游戏!")


# 创建小学生对象
pupil = Pupil("小菲", 11, 10, "女")


# pupil.study()
# 创建中学生对象,并且调用study方法
# Middle("国涛",15,120,"男",120,150).study()
# 创建大学生对象,并且调用study方法
# Univercity("渣渣辉",24,999,"男").study()


# 2.

# 父类
class Animal(object):
    def __init__(self, name, age, sex, skill):
        self.name = name
        self.age = age
        self.sex = sex
        self.skill = skill


# 犬类
class Dog(Animal):
    def __str__(self):
        return f''' 
宠物狗:
昵称:{self.name}
年龄：{self.age}
性别：{self.sex}
才艺: {self.skill}
        '''


# 猫类
class Cat(Animal):
    def __str__(self):
        return f''' 
宠物猫:
昵称:{self.name}
年龄：{self.age}
性别：{self.sex}
才艺: {self.skill}     
        '''


class Person(object):
    def __init__(self, madom, girl):
        self.madom = madom
        self.girl = girl

    def introduce(self, dog, cat):
        print(f"主人{self.madom}向客人{self.girl}介绍自己的宠物狗和宠物猫", dog, cat)


# dog = Dog("奇奇",18,"雌","会两条腿走路")

# cat = Cat("贝贝",9,"雄","会装死")

# Person("杨夫人","李小姐").introduce(dog,cat)

# 3.

# 班级类
class Grade(object):
    def __init__(self, name, stu_list):
        self.name = name
        self.stu_list = stu_list
        # stu_list = [stu1,stu2,stu3....]

    # 显示所有学生的方法
    def show_stu_list(self):
        for stu in self.stu_list:
            print(stu)

    # 根据学号查找学生
    def find_stu_by_num(self, num):
        for stu in self.stu_list:
            if stu.num == num:
                print(stu)
                break
        else:
            print("查无此人!")

    # 添加学生的方法
    def add_stu(self, new_stu):
        self.stu_list.append(new_stu)

        # 删除学生的方法

    def add_stu(self, num):
        for stu in self.stu_list:
            if stu.num == num:
                self.stu_list.remove(stu)
                break

    # 根据学号升序排序
    def sort_by_num(self):
        self.stu_list.sort(key=lambda stu: stu.num)
        self.show_stu_list()

    # 根据成绩降序
    def sort_by_score(self):
        self.stu_list.sort(key=lambda stu: stu.score, reverse=True)
        self.show_stu_list()


# 学生类
class Student1(object):
    def __init__(self, name, age, num, score):
        self.name = name
        self.age = age
        self.num = num
        self.score = score

    def __str__(self):
        return f"姓名:{self.name} 年龄:{self.age} 学号{self.num} 成绩{self.score}"


stu1 = Student1("放舟", 21, 110, 99)
stu2 = Student1("连英", 22, 113, 97)
stu3 = Student1("欧阳", 23, 112, 79)
stu4 = Student1("中文", 24, 111, 88)

grade = Grade("python2106班", [stu1, stu2, stu3, stu4])
# grade.show_stu_list()
print(type(grade.stu_list[0]))
# grade.find_stu_by_num(113)

# grade.sort_by_num()
grade.sort_by_score()
